package com.szm.userserver.mapperimpl;

import com.szm.userserver.entity.User;
import com.szm.userserver.mapper.UserRedisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository("UserRedisDao")
public class UserRedisDaoImpl implements UserRedisDao {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Resource(name = "stringRedisTemplate")
    ValueOperations<String,String> valueOperations;

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Resource(name = "redisTemplate")
    ValueOperations<Object,Object> valueOperationsObj;

    public String getUser(String userName){
       return valueOperations.get(userName);
    }

    public void setUser(User user){
        valueOperations.set(user.getUsername(),user.getUsername());
    }

    public void delUser(String userName){
        stringRedisTemplate.delete(userName.toString());
    }


    public Object getObj(Object object){
      return valueOperationsObj.get(object);
    }
}
